﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Connect
{
    public class ScriptSQL
    {

        public static string LikeSearch(string Nguon, string Column)
        {
            if (string.IsNullOrEmpty(Nguon) == true)
            {
                return "";
            }
            else
            {
                int dem = 0;
                Nguon = Nguon.Trim().TrimStart().TrimEnd();
                for (int i = 0; i < Nguon.Length; i++)
                {
                    if (Nguon[i] == ' ')
                    {
                        dem++;
                    }
                }
                if (dem==0)
                {
                    return "";
                }
                string sql = " where " + Column + " like N'%";

                string[] Day = Nguon.Split(' ');
                for (int i = 0; i < dem; i++)
                {
                    if (Day[i].Length>4)
                    {
                          sql += Day[i] + "%' and " + Column + " like N'%";
                    }
                  
                }

                return sql.Remove(sql.LastIndexOf("and " + Column + " like N'%"), ("and " + Column + " like N'%").Length);
            }
        }
    }
}
